package cn.template.models;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<User, Long> {
    @Query(value = "SELECT * FROM users u WHERE u.company_id = ?1 and u.name like ?2",
            countQuery = "SELECT count(*) FROM users u WHERE u.company_id = ?1 and u.name like ?2",
            nativeQuery = true)
    Page<User> findAllByCompanyAndName(long company_id, String name, Pageable pageable);

    @Query(value = "SELECT * FROM users u WHERE u.company_id = ?1",
            countQuery = "SELECT count(*) FROM users u WHERE u.company_id = ?1",
            nativeQuery = true)
    Page<User> findAllByCompany(long company_id, Pageable pageable);

    User getByUsername(String username);
}
